<template>
<div>
  <a-modal
    title="新增幼儿"
    width="60%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :span="8">
            <a-form-item
              label="幼儿姓名"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input placeholder="请输入幼儿姓名" v-decorator="['name', {rules: [{required: true, message: '请输入幼儿姓名！'}]}]" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item
              label="学号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              has-feedback
            >
              <a-input placeholder="请输入学号" v-decorator="['studentNumber', {rules: [{required: false, message: '请输入学号！'}]}]" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item
              label="班级"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              has-feedback
            >
              <a-select allowClear placeholder="请选择班级！" v-decorator="['classesId', {rules: [{required: false, message: '请选择班级！'}]}]">
                <a-select-option v-for="item in classList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="8">
            <a-form-item
              label="出生日期"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              has-feedback
            >
              <a-date-picker class="fullwidth" :format="dateFormat" :valueFormat="dateFormat" v-decorator="['birthday', {rules: [{required: true, message: '请选择出生日期！'}]}]" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item
              label="性别"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              has-feedback
            >
              <a-radio-group v-decorator="['gender', {rules: [{required: true, message: '请选择幼儿性别'}]}]">
                <a-radio :value="1">男</a-radio>
                <a-radio :value="2">女</a-radio>
                <a-radio :value="0">未知</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
          
          <a-col :span="8">
            <a-form-item
              label="家庭住址"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              has-feedback
            >
              <a-input placeholder="请输入家庭住址" type="textarea" v-decorator="['homeAddress', {rules: [{required: false, message: '请输入家庭住址！'}]}]" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
      <add-family ref="addFamily" @ok="handleOk" />
  </div>
</template>

<script>
import { STable, XCard, XDown } from '@/components'
  import { childrenAdd, childrenPage } from '@/api/modular/children/childManage'
  import { parentPage } from '@/api/modular/parent/parentManage'
  import addFamily from './addFamily'
  import moment from 'moment';
  export default {
    components: {
      XDown,
      XCard,
      STable,
      addFamily,
    },
    props: {
      classList: {type: Array},
    },
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 18 }
        },
        
        // 表头
        columns: [
          {
            title: '家长姓名',
            dataIndex: 'name'
          },
          {
            title: '与幼儿关系',
            dataIndex: 'studentNumber'
          },
          {
            title: '手机',
            dataIndex: 'birthday'
          },
          {
            title: '工作单位',
            dataIndex: 'className'
          },
          {
            title: '学历',
            dataIndex: 'registeredDay'
          },
          {
            title: '微信平台',
            dataIndex: 'fdsfsd'
          }
        ],
        loadfamilyData:parameter => {
          return parentPage(Object.assign(parameter, this.queryParam)).then((res) => {
            return res.data
          })
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this),
        classList1: [],
        dateFormat: 'YYYY-MM-DD',
      }
    },
    created(){
      this.columns.push({
        title: '操作',
        width: '200px',
        dataIndex: 'action',
        scopedSlots: { customRender: 'action' }
      })
    },
    methods: {
      // 初始化方法
      add (record) {
        this.classList1 = this.classList;
        this.visible = true;
      },

      classroomchange(val){
        console.log(val)
        let _classroom = this.classroom1.find(item => {return item.id === val})
        this.classroomName = _classroom.cRoomName;
      },

      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            values['birthday'] = moment(values.birthday).format('YYYY-MM-DD')
            childrenAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.visible = false
                this.confirmLoading = false
                this.$emit('ok', values)
                this.form.resetFields()
              } else {
                this.$message.error('新增失败：' + res.message)
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      },
      shanchujiazhang(){

      },
      handleOk(){
        this.$refs.familytable.refresh()
        
      },

    }
  }
</script>
